package servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import defecto.ConectorHttp;
import defecto.SipodDAO;
import defecto.SipodVO;

/**
 * Servlet implementation class Tester
 */
public class Tester extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Tester() {
	super();
	// TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {
	// Variables de manejo de peticion
	PrintWriter printWrit = response.getWriter();
	BufferedReader bfr = null;
	response.setContentType("text/html");
	// variables locales
	String tipo = request.getParameter("tipo");
	String numero = request.getParameter("numero");
	try {
	    if (tipo.equals("")) {
		printWrit.println("No enviaste el tipo de documento");
	    } else if (numero.equals("")) {
		printWrit.println("No enviaste el numero de documento");
	    }

	    // Uso de la llamada SSL HTTPS
	    SipodDAO sipoddao = new SipodDAO();
	    SipodVO valueObject = SipodDAO.createValueObject();
	    valueObject = sipoddao.getRegistry(tipo, numero);

	    //valueObject = sipoddao.getRegistry(tipo, numero);

	    // Print del resultado
	    printWrit
		    .println("<strong>CONSULTA SISTEMA NACIONAL DE DESPLZADOS SIPOD</strong>");
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Tipo Documento:</strong> "
		    + valueObject.getTipoDocumento());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Numero Documento:</strong> "
		    + valueObject.getDocumento());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Nombre:</strong> "
		    + valueObject.getNombre1());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Apellido:</strong> "
		    + valueObject.getApellido1());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Codigo SIPOD:</strong> "
		    + valueObject.getId());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Fecha Declaracion:</strong> "
		    + valueObject.getFechaDeclaracion());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Fecha Vinculacion:</strong> "
		    + valueObject.getFechaVinculacion());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Fecha Desplazamiento:</strong> "
		    + valueObject.getFechaDesplaz());
	    printWrit.println("<br/>");
	    printWrit
		    .println("<strong>Sexo:</strong> " + valueObject.getSexo());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Departamento/Municipio:</strong> "
		    + valueObject.getDeparMunDeclaracion());
	    printWrit.println("<br/>");
	    printWrit.println("<strong>Relacion:</strong> "
		    + valueObject.getRelacion());

	} finally {
	 
	}
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {
	// TODO Auto-generated method stub
    }

}
